<?php
namespace Home\Controller;

use Component\Home2Controller;

class ResController extends Home2Controller
{
    //框架结构
    public function res(){
        $this->display();
    }

    //下部页面
    public function bottom(){
        $ress=D("Message");
        $total=$ress->where("message_introduce like '%".$_SESSION["word"]."%'")->count();
        $per=10;
        $page = new \Component\Page($total,$per);
        $sql = "select * from sw_message where message_introduce like '%".$_SESSION["word"]."%' or username like '%".$_SESSION["word"]."%' order by message_time desc " ;
        $sql=$sql.$page->limit;
        $info=$ress->query($sql);
        $pagelist=$page->fpage();

        $comment=D("Comment");
        foreach($info as $k => $v){
            $c=$comment->where("message_id='".$v["message_id"]."'")->count();
            $info[$k]["comment_count"]=$c;
        }

        $this->assign("info",$info);
        $this->assign("pagelist",$pagelist);
        $this->display();
    }

}
